<template>
	<view class="apply-list">
		<uni-load-more class="loading-class" iconType="auto" v-if="applyLoading" status="loading" color="#999999" />
		<view v-else>

			<view class="apply-item" v-if="isApplyShow" v-for="(item, index) in alreadyApplyList" :key="index"
				@click.stop="handleAlreadyApplyDetails(item)">
				<view class="apply-item-main">
					<view class="apply-item-left">
						<image class="apply-item-left-image"
							src="https://biapi.vaubang.cn/UploadFiles/Images/apply-img.png" mode="aspectFit"></image>
					</view>
					<view class="apply-item-right">
						<view class="apply-item-title">{{item.name}}</view>
						<view class="apply-item-type">类型：{{item.type}}</view>
						<view class="apply-item-date">集训时间：{{item.beginTime}} 至 {{item.endTime}}</view>
						<view class="apply-item-time">报名截止时间：{{item.deadline}}</view>
					</view>
				</view>
				<!-- <view class="apply-item-tips">
					<text class="units">*</text>
					<text class="tips-text">{{item.tips}}</text>
				</view> -->
			</view>
			<view class="no-template-tips" v-else>
				<van-icon class="tips-icon" name="warn-o" />
				<p class="tips-text">暂无报名信息，快去报名吧！</p>
			</view>

		</view>

	</view>
</template>

<script>
	import apiRqs from "@/api/api-request.js";
	export default {
		data() {
			return {
				userOpenid: "",
				alreadyApplyList: [],
				applyLoading: false,
				isApplyShow: false,
			}
		},
		onShow() {
			this.handleApplyList();
		},
		onLoad(option) {
			this.userOpenid = option.openid;
		},
		methods: {
			// 获取已报名列表
			handleApplyList() {
				var that = this;
				that.applyLoading = true;
				let rqs = {
					"paged": {
						"pageSize": 9999,
						"pageIndex": 1,
						"orderBy": ""
					},
					"openId": this.userOpenid
				};
				apiRqs._getAlreadyApplyList(rqs).then((res) => {
					that.applyLoading = false;
					console.log('我的报名列表', res);
					if (res.code == 200) {
						let alreadyApplyData = JSON.parse(JSON.stringify(res.data.data));
						for (let i = 0; i < alreadyApplyData.length; i++) {
							alreadyApplyData[i].beginTime = alreadyApplyData[i].beginTime.split(" ")[0];
							alreadyApplyData[i].endTime = alreadyApplyData[i].endTime.split(" ")[0];
							alreadyApplyData[i].deadline = alreadyApplyData[i].deadline.split(" ")[0];
						}
						that.alreadyApplyList = alreadyApplyData;
						if (res.data.totalRecords > 0) {
							that.isApplyShow = true;
						} else {
							that.isApplyShow = false;
						}
					} else {
						getApp().showToast(res.msg);
					}
				}).catch((err) => {
					console.log('err', err);
				})
			},
			handleAlreadyApplyDetails(item) {
				uni.setStorageSync("alreayApplyInfo", item);
				uni.navigateTo({
					url: "/packageA/workbench/history-apply-detail?openid=" + this.userOpenid
				})
			},
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f5f5f5;
	}

	.apply-list {
		.no-template-tips {
			margin-top: 50px;
			display: flex;
			flex-direction: column;
			align-items: center;

			.tips-icon {
				font-size: 50px;
				color: #999999;
			}

			.tips-text {
				font-size: 14px;
				color: #999999;
				margin-top: 10px;
			}
		}

		.already-apply {
			margin: 10px 15px;
			display: flex;
			justify-content: flex-end;

			.already-apply-icon {
				font-size: 15px;
				color: #008aff;
				margin-right: 5px;
			}

			.already-apply-text {
				font-size: 13px;
				color: #008aff;
			}
		}

		.apply-item {
			padding: 10px;
			background-color: #fff;
			box-shadow: 0 0 8px rgba(0, 0, 0, 0.05);
			margin-top: 10px;

			&:first-child {
				margin-top: 0;
			}

			.apply-item-main {
				display: flex;

				.apply-item-left {
					width: 93px;
					height: 93px;
					border: 1px solid #f5f5f5;
					padding: 0px 4px;
					box-sizing: border-box;

					.apply-item-left-image {
						width: 100%;
						height: 100%;
					}
				}

				.apply-item-right {
					margin-left: 5px;

					.apply-item-title {
						font-size: 15px;
						color: #000;
						margin-top: 3px;
					}

					.apply-item-type {
						font-size: 12px;
						color: #666;
						margin-top: 5px;
					}

					.apply-item-date,
					.apply-item-time {
						font-size: 12px;
						color: #666;
						margin-top: 5px;
					}

					.apply-btn {
						border: none;
						background-color: #008aff;
						color: #fff;
						width: 100px;
						height: 30px;
						text-align: center;
						line-height: 30px;
						border-radius: 4px;
						font-size: 14px;

						&:active {
							background-color: #0076DB;
						}
					}
				}
			}

			.apply-item-tips {
				font-size: 12px;
				color: #999;
				margin-top: 5px;

				.units {
					color: red;
					margin-right: 2px;
				}
			}
		}
	}
</style>
